<?php
/**
 * 以下展示适配器模式的示例调用
 * 【目的】：将一个类的接口转换成客户希望的另外一个接口，Adapter模式使得原来由于接口不兼容而不能一起工作的那些类可以一起工作
 * Created by PhpStorm.
 * User: liangtiehui
 * Date: 2015/12/22
 * Time: 22:46
 */

namespace Adapter;

require "ErrorObject.php";
require "LogToConsole.php";
require "LogToCsv.php";
require "LogToCsvAdapter.php";

$test = new Test();

if ($_GET['type']) {
    if ($_GET['type'] == 1) {
        $test->logConsole();
    } else if ($_GET['type'] == 2) {
        $test->logCsv();
    }
}

class Test
{
    public function logConsole()
    {
        $error = new \Adapter\ErrorObject("404:not found");
        $log = new \Adapter\LogToConsole($error);
        $log->write();
    }

    public function logCsv()
    {
        $error = new LogToCsvAdapter("404:not found");
        $log = new LogToCsv($error);
        $log->write();
    }
}